import {
  api,
  util
} from "../util"
import authorize from './authorize.js'
import {
  pagesInfo
} from "../router";
const app = getApp();
export class CollectData {
  constructor(param) {
    var entity = authorize.getEntity() || authorize.getDefault();
    var dic = pagesInfo[param.pageKey] || {};
    this.data = {
      uuid: param.uuid,
      appKey: api.appId,//api.secret, 
      host: api.domain,
      apiDomain: api.domain,
      pageTitle: dic.desc,
      pageKey: dic.key,
      terminal: "WXApp",
      version: api.publicVersion,
      viewTime: new Date().getTime(),
      appid:api.appId,
      terminalId:5,
      detailText:'',
      user: {
        proprietor: app.dns.proprietor,
        proprietorId: parseInt(app.dns.proprietorId),
        fkFlag: app.dns.proprietor,
        fkId: parseInt(app.dns.proprietorId),
        fkWay: app.dns.fkWay,
        loginFKFlag: entity.fkFlag,
        loginFKId:parseInt(entity.fkId),
        loginManagerId: entity.manager.ManagerId,
      }
    }
  }
  onEnter(dataJson = {}) {
    var param = this.data;
    let dt = new Date();
    wx.getSystemInfo({
      success: (c) => {
        let opts = Object.assign({
          leaveTime: 0, // 离开页面的时间
          delay: 0, // 在此页面停留的时间,离开时时间-进入时间
          year: dt.getFullYear(), // 访问时间年
          month: dt.getMonth() + 1, // 访问时间月
          day: dt.getDate(), // 访问时间日
          hour: dt.getHours(), // 访问时间时
          minute: dt.getMinutes(), // 访问时间分
          detailText:'',
          resolution: {
            screenWidth: c.screenWidth,
            screenHeight: c.screenHeight,
            clientWidth: c.windowWidth,
            clientHeight: c.windowHeight,
            language: c.language,
            version: c.version,
            system: c.system,
            platform: c.platform,
            fontSizeSetting: c.fontSizeSetting,
            sDKVersion: c.SDKVersion
          }
        }, param, dataJson);
        util.post_api(api.host +api.wiresharkApi, opts);
      }
    })

  }
  onLeave(dataJson = {}) {
    var param = this.data;
    let dt = new Date();
    let stayTime = dt.getTime() - param.viewTime;
    let opts = Object.assign({
      delay: stayTime,
      leaveTime: dt.getTime()
    }, param, dataJson);
    util.post_api(api.host +api.wiresharkApi, opts);
  }
  /**
   * 页面请求
   */
  pageRequest(dataJson) {
    var param = this.data;
    if (dataJson) {
      param = util.mergeJsonObject(this.data, dataJson);
    }
    util.post_api(api.host+api.wiresharkApi, param);
  }
}